#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define pd(n) printf("%d", (n))
#define pld(n) printf("%lld", n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
const int N = 2e5;
#define INF 0x7fffffff
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//
void solve()
{
	int n;
	sd(n);
	int num_1 = 0;//突出
	int num_2 = 0;//凹陷
	for (int i = 0; i < n*n-1; i++)
	{
		string s1;
		cin >> s1;
		for (auto& k : s1)
		{
			if (k == '1') num_1++;
			if (k == '2') num_2++;
		}

	}
	if (num_1 > num_2) cout << 10 + num_1 - num_2 << '\n';
	if (num_1 < num_2) cout << 10 - (num_2 - num_1) << '\n';
	if (num_1 == num_2) cout << 10 << '\n';
}
int main()
{
	int T;
	sd(T);
	while (T--)
	{
		solve();
	}
	return 0;
}